﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[spObtenComboEstudios](
	@pnIdLaboratorio INT,
	@pnIncPaq TINYINT
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	SELECT	d.IdEstudio,
			d.NombreEstudio,
			0 AS EsPaquete
	INTO	#tmpEst
	FROM	dbo.CatEstudio (NOLOCK) d
	WHERE	d.IdLaboratorio = @pnIdLaboratorio
	AND		ISNULL(d.BajaLogica,0)	= 0
	ORDER BY NombreEstudio;
	
	IF @pnIncPaq = 1
	BEGIN
		INSERT	#tmpEst
		        ( IdEstudio, NombreEstudio, EsPaquete )
		SELECT	IdPaquete, Descripcion, 1
		FROM	dbo.PaqueteEstudio
		WHERE	ISNULL(BajaLogica,0)	= 0
	END

	SELECT	IdEstudio ,
	        NombreEstudio,
	        EsPaquete
	FROM	#tmpEst
	ORDER BY NombreEstudio
	
	SET NOCOUNT OFF;
END